<template>
  <div class="auth">
    <bk-header></bk-header>
    <div class="title">登录</div>
    <Row class="auth-content" type="flex" align="middle">
      <Col span="12" class="auth-form" offset="6">
        <Form :model="login" :label-width="80">
          <div class="form-title">账号</div>
          <input placeholder="账号" v-model="login.username" class="form-ipt"></input>
          <div class="form-title">密码</div>
          <input
            placeholder="密码"
            type="password"
            v-model="login.password"
            class="form-ipt"
          ></input>

            <button long type="primary" @click="login_submit" class="btn">登录</button>
            <input type="checkbox" class="checkbox">记住我
            <br>
            <br>
            <router-link to='/'>忘记密码</router-link>
            <span style="margin-left:40px;">没有账号？点击<router-link to='/register'>注册</router-link></span>
          
        </Form>
      </Col>
    </Row>
  </div>
</template>

<script>
export default {
  data() {
    return {
      login: {
        username: "",
        password: ""
      },
      register: {
        username: "",
        password: "",
        password2: ""
      },
      name: "登录"
    };
  },
  methods: {
    login_submit() {
      this.$api.auth.login(this.login.username, this.login.password).then(res => {
        this.$toast.success("登录成功");
        this.$store.commit("setLogin", this.login.username);
        if (res.token) {
          localStorage.setItem("token", res.token);
        }
        this.$router.push("/");
      });
    },
    sign_submit() {
      if (this.register.password !== this.register.password2 || this.register.password === "") {
        this.$toast.info("两次密码不一致");
        return;
      }
      this.$api.auth.register(this.register.username, this.register.password).then(() => {
        this.$toast.success("注册成功");
        this.register = {
          username: "",
          password: "",
          password2: ""
        };
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.auth {
  height: 100%;
  overflow: hidden;
  .auth-content {
    height: 100%;
  }
  .title {
    height: 120px;
    text-align: center;
    box-sizing: content-box;
    border: 10px solid #fff;
    color: #fff;
    border-radius: 4px;
    background: rgba($color: #fff, $alpha: 0.2);
    width: 40%;
    margin: 50px auto;
    font-size: 54px;
    line-height: 120px;
  }
  .form-title {
    color: #aaa;
    margin: 10px 0;
  }
  .form-ipt {
    height: 38px !important;
    line-height: 38px;
    width:100%;
    padding: 0 16px;
    border-radius: 0;
    margin-bottom: 20px;
    outline: 1px solid #dfdfdf;
    border: none;
    color: #933;
    // transition: 0.3s;
  }
  .auth-form {
    background: #fff;
    padding: 30px;
    min-height: 300px;
    box-shadow: 0 0 10px #fff;
    border-radius: 4px;
    outline: 1px dashed #933 inset;
  }
  .btn{
    height: 40px;
    background: linear-gradient(to right ,#933,#a44);
    width: 120px;
    color: #fff;
    border: none;
    outline: none;
    box-shadow: 0px 0px 5px #933;
    transition: 0.3s;
    &:hover{
      box-shadow: 1px 2px 5px #933;
    }
  }
  .checkbox{
    margin-left: 20px;
    margin-right: 4px;
    height: 14px;
    width: 14px;
  }
}
</style>
